/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package TapestryModel.impl;

import TapestryModel.Activation;
import TapestryModel.ActivationMapping;
import TapestryModel.ContentData;
import TapestryModel.PrimitiveType;
import TapestryModel.TapestryModelPackage;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Activation Mapping</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link TapestryModel.impl.ActivationMappingImpl#getType <em>Type</em>}</li>
 *   <li>{@link TapestryModel.impl.ActivationMappingImpl#getData <em>Data</em>}</li>
 *   <li>{@link TapestryModel.impl.ActivationMappingImpl#getName <em>Name</em>}</li>
 *   <li>{@link TapestryModel.impl.ActivationMappingImpl#getOwner <em>Owner</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ActivationMappingImpl extends EObjectImpl implements ActivationMapping {
    /**
     * The default value of the '{@link #getType() <em>Type</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getType()
     * @generated
     * @ordered
     */
    protected static final PrimitiveType TYPE_EDEFAULT = PrimitiveType.STRING;

    /**
     * The cached value of the '{@link #getType() <em>Type</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getType()
     * @generated
     * @ordered
     */
    protected PrimitiveType type = TYPE_EDEFAULT;

    /**
     * The cached value of the '{@link #getData() <em>Data</em>}' reference list.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getData()
     * @generated
     * @ordered
     */
    protected EList<ContentData> data;

    /**
     * The default value of the '{@link #getName() <em>Name</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getName()
     * @generated
     * @ordered
     */
    protected static final String NAME_EDEFAULT = null;

    /**
     * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @see #getName()
     * @generated
     * @ordered
     */
    protected String name = NAME_EDEFAULT;

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    protected ActivationMappingImpl() {
        super();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    protected EClass eStaticClass() {
        return TapestryModelPackage.Literals.ACTIVATION_MAPPING;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public PrimitiveType getType() {
        return type;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setType(PrimitiveType newType) {
        PrimitiveType oldType = type;
        type = newType == null ? TYPE_EDEFAULT : newType;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.ACTIVATION_MAPPING__TYPE, oldType, type));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public EList<ContentData> getData() {
        if (data == null) {
            data = new EObjectResolvingEList<ContentData>(ContentData.class, this, TapestryModelPackage.ACTIVATION_MAPPING__DATA);
        }
        return data;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public String getName() {
        return name;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setName(String newName) {
        String oldName = name;
        name = newName;
        if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.ACTIVATION_MAPPING__NAME, oldName, name));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public Activation getOwner() {
        if (eContainerFeatureID != TapestryModelPackage.ACTIVATION_MAPPING__OWNER) return null;
        return (Activation)eContainer();
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public NotificationChain basicSetOwner(Activation newOwner, NotificationChain msgs) {
        msgs = eBasicSetContainer((InternalEObject)newOwner, TapestryModelPackage.ACTIVATION_MAPPING__OWNER, msgs);
        return msgs;
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    public void setOwner(Activation newOwner) {
        if (newOwner != eInternalContainer() || (eContainerFeatureID != TapestryModelPackage.ACTIVATION_MAPPING__OWNER && newOwner != null)) {
            if (EcoreUtil.isAncestor(this, newOwner))
                throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
            NotificationChain msgs = null;
            if (eInternalContainer() != null)
                msgs = eBasicRemoveFromContainer(msgs);
            if (newOwner != null)
                msgs = ((InternalEObject)newOwner).eInverseAdd(this, TapestryModelPackage.ACTIVATION__PARAM, Activation.class, msgs);
            msgs = basicSetOwner(newOwner, msgs);
            if (msgs != null) msgs.dispatch();
        }
        else if (eNotificationRequired())
            eNotify(new ENotificationImpl(this, Notification.SET, TapestryModelPackage.ACTIVATION_MAPPING__OWNER, newOwner, newOwner));
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case TapestryModelPackage.ACTIVATION_MAPPING__OWNER:
                if (eInternalContainer() != null)
                    msgs = eBasicRemoveFromContainer(msgs);
                return basicSetOwner((Activation)otherEnd, msgs);
        }
        return super.eInverseAdd(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
        switch (featureID) {
            case TapestryModelPackage.ACTIVATION_MAPPING__OWNER:
                return basicSetOwner(null, msgs);
        }
        return super.eInverseRemove(otherEnd, featureID, msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
        switch (eContainerFeatureID) {
            case TapestryModelPackage.ACTIVATION_MAPPING__OWNER:
                return eInternalContainer().eInverseRemove(this, TapestryModelPackage.ACTIVATION__PARAM, Activation.class, msgs);
        }
        return super.eBasicRemoveFromContainerFeature(msgs);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public Object eGet(int featureID, boolean resolve, boolean coreType) {
        switch (featureID) {
            case TapestryModelPackage.ACTIVATION_MAPPING__TYPE:
                return getType();
            case TapestryModelPackage.ACTIVATION_MAPPING__DATA:
                return getData();
            case TapestryModelPackage.ACTIVATION_MAPPING__NAME:
                return getName();
            case TapestryModelPackage.ACTIVATION_MAPPING__OWNER:
                return getOwner();
        }
        return super.eGet(featureID, resolve, coreType);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @SuppressWarnings("unchecked")
    @Override
    public void eSet(int featureID, Object newValue) {
        switch (featureID) {
            case TapestryModelPackage.ACTIVATION_MAPPING__TYPE:
                setType((PrimitiveType)newValue);
                return;
            case TapestryModelPackage.ACTIVATION_MAPPING__DATA:
                getData().clear();
                getData().addAll((Collection<? extends ContentData>)newValue);
                return;
            case TapestryModelPackage.ACTIVATION_MAPPING__NAME:
                setName((String)newValue);
                return;
            case TapestryModelPackage.ACTIVATION_MAPPING__OWNER:
                setOwner((Activation)newValue);
                return;
        }
        super.eSet(featureID, newValue);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public void eUnset(int featureID) {
        switch (featureID) {
            case TapestryModelPackage.ACTIVATION_MAPPING__TYPE:
                setType(TYPE_EDEFAULT);
                return;
            case TapestryModelPackage.ACTIVATION_MAPPING__DATA:
                getData().clear();
                return;
            case TapestryModelPackage.ACTIVATION_MAPPING__NAME:
                setName(NAME_EDEFAULT);
                return;
            case TapestryModelPackage.ACTIVATION_MAPPING__OWNER:
                setOwner((Activation)null);
                return;
        }
        super.eUnset(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public boolean eIsSet(int featureID) {
        switch (featureID) {
            case TapestryModelPackage.ACTIVATION_MAPPING__TYPE:
                return type != TYPE_EDEFAULT;
            case TapestryModelPackage.ACTIVATION_MAPPING__DATA:
                return data != null && !data.isEmpty();
            case TapestryModelPackage.ACTIVATION_MAPPING__NAME:
                return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
            case TapestryModelPackage.ACTIVATION_MAPPING__OWNER:
                return getOwner() != null;
        }
        return super.eIsSet(featureID);
    }

    /**
     * <!-- begin-user-doc -->
     * <!-- end-user-doc -->
     * @generated
     */
    @Override
    public String toString() {
        if (eIsProxy()) return super.toString();

        StringBuffer result = new StringBuffer(super.toString());
        result.append(" (type: ");
        result.append(type);
        result.append(", name: ");
        result.append(name);
        result.append(')');
        return result.toString();
    }

} //ActivationMappingImpl
